<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.gzgi.framework.config.database.*"%>
<%@ include file="/pages/system/checkAdmin.jsp"%>
<%
       String contextPath = request.getContextPath();
	   String id = request.getParameter("id");
	   if(id == null){
		   id="mysql";
	   }
	   DataSourceConfig cfg = new DataSourceConfig();
	   Map dataMap = cfg.getDatabaseMap();
	   Database database = (Database) dataMap.get(id);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数据源配置</title>
 
<link rel="stylesheet" type="text/css"
	href="<%=request.getContextPath()%>/pages/styles/styles.css" />

<script language="JavaScript">
  String.prototype.trim = function() {
     return this.replace(/(^\s*)|(\s*$)/g, "");
  }

 function submitRequest(form, actionType){
    var host = document.getElementById("host").value.trim();
	var databaseName = document.getElementById("databaseName").value.trim();
	document.getElementById("actionType").value = actionType;

    if(host == ""){
		alert("数据库服务器地址不能为空！");
		document.getElementById("host").focus();
		return ;
	 }
	if(databaseName == ""){
		alert("数据库名称不能为空！");
		document.getElementById("databaseName").focus();
		return ;
	 }

    if(actionType == "reconfig"){
       if(confirm("您真的要重新配置数据源，确认吗？")){
	        form.submit();
	   }
	}else{
		form.submit();
	}

 }

</script>
<body>
<center><br>
<br>

<form name="iForm" method="post" action="saveDataSource.jsp"	class="x-form">
<input type="hidden" id="actionType"	name="actionType" value="test">
<div style="width: 585px;" align="center">
<div class="content-block">
<br>
<div class="x_content_title">
    <img src="<%=request.getContextPath()%>/pages/images/window.png" alt="数据源配置">&nbsp;数据源配置
</div>
<fieldset class="x-fieldset" style=" width: 95%;">
<legend>基本属性</legend>
<br>
<table border=0 cellspacing=0 cellpadding=2>
<tbody>
 <tr class="x-content-hight">
  <td style="width: 140px; padding-right: 10px">
      <span class="field-name-required">数据库类型 *</span>
  </td>
  <td> 
	<select name="id">
		<%
			Iterator iterator = dataMap.keySet().iterator();
			while(iterator.hasNext()){
				String key = (String)iterator.next();
				Database db = (Database)dataMap.get(key);
		%>
		<option value="<%=key%>"><%=db.getName()%></option>
		<% }%>
    </select>
  </td>
 </tr>
 <tr class="x-content-hight">
  <td style="width: 140px; padding-right: 10px">
      <span class="field-name-required">数据库服务器地址 *</span>
  </td>
  <td> 
    <input id="host" name="host" size="30" class="x-text" maxlength="255" value="">
  </td>
  </tr>
   <tr class="x-content-hight">
  <td style="width: 140px; padding-right: 10px">
      <span class="field-name-required">数据库名称 *</span>
  </td>
  <td> 
    <input id="databaseName"
	name="databaseName" size="30" class="x-text" maxlength="255"
	value="">
  </td>
  </tr>
  <tr class="x-content-hight">
  <td style="width: 140px; padding-right: 10px">
      <span>数据库端口</span>
  </td>
  <td> 
    <input id="port"
	name="port" size="30" class="x-text" maxlength="5" value="">（使用默认端口不用填写）
  </td>
  </tr>
  <tr class="x-content-hight">
  <td style="width: 140px; padding-right: 10px">
      <span>用户名</span>
  </td>
  <td> 
    <input id="username"
	name="username" size="30" class="x-text" maxlength="255" value="">
  </td>
  </tr>
  <tr class="x-content-hight">
  <td style="width: 140px; padding-right: 10px">
      <span>密码</span>
  </td>
  <td> 
    <input id="password"
	name="password" type="password" size="31" class="x-text"
	maxlength="255" value="">
  </td>
  </tr>
 </tbody>
 </table>

</fieldset>
<div align="center">
<br/><br/>
<input type="button" class="button" value="重新配置"
	onclick="javascript:submitRequest(this.form, 'reconfig');" /> <input
	type="button" class="button" value="测试连接"
	onclick="javascript:submitRequest(this.form, 'test');" /> <br />
<br/>
</div>
</div>
</form>
</center>
<br />
<br />